/**
 * 合作网点管理初始化
 */
var TCooperationDot = {
    id: "TCooperationDotTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
TCooperationDot.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: 'id', field: 'id', visible: true, align: 'center', valign: 'middle'},
            {title: '企业', field: 'fullname', visible: true, align: 'center', valign: 'middle'},
            {title: '网点名称', field: 'dotName', visible: true, align: 'center', valign: 'middle'},
            {title: '联系人', field: 'contactsName', visible: true, align: 'center', valign: 'middle'},
            {title: '联系号码', field: 'contactsPhone', visible: true, align: 'center', valign: 'middle'},
            {title: '数据互通编号', field: 'code', visible: true, align: 'center', valign: 'middle'},
            {title: '省份', field: 'proPlaceName', visible: true, align: 'center', valign: 'middle'},
            {title: '城市', field: 'cityPlaceName', visible: true, align: 'center', valign: 'middle'},
            {title: '区县', field: 'areaPlaceName', visible: true, align: 'center', valign: 'middle'},
            {title: '结算方式', field: 'settlementName', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
TCooperationDot.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        TCooperationDot.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加合作网点
 */
TCooperationDot.openAddTCooperationDot = function () {
    var index = layer.open({
        type: 2,
        shade:0.01,
        title: '添加合作网点',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/tCooperationDot/tCooperationDot_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看合作网点详情
 */
TCooperationDot.openTCooperationDotDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            shade:0.01,
            title: '合作网点详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/tCooperationDot/tCooperationDot_update/' + TCooperationDot.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除合作网点
 */
TCooperationDot.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/tCooperationDot/delete", function (data) {
            Feng.success("删除成功!");
            TCooperationDot.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("tCooperationDotId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询合作网点列表
 */
TCooperationDot.search = function () {
    var queryData = {};
    queryData['name'] = $("#condition").val();
    TCooperationDot.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = TCooperationDot.initColumn();
    var table = new BSTable(TCooperationDot.id, "/tCooperationDot/list", defaultColunms);
    // table.setPaginationType("client");
    TCooperationDot.table = table.init();
    layui.use('layer', function () {

    })
});
